<template>
	<view class="setPage">
		<u-navbar title="设置" :autoBack="true" :placeholder="true">
		</u-navbar>

		<view class="">
			<view class="titleBox">
				<image
					:src="role==1?'https://mp.blrwworkshop.com/imgs/student_line.png' :'https://mp.blrwworkshop.com/imgs/lines.png' "
					mode=""></image>
				<view class="">
					当前学生信息
				</view>
			</view>

			<view class="messageContent">
				<view class="messageItem">
					<view class="lable">
						学生姓名
					</view>
					<view class="value">
						{{studentInfo.student.name || ""}}
					</view>
				</view>
				<view class="messageItem">
					<view class="lable">
						性别
					</view>
					<view class="value">
						{{studentInfo.student.sex==0?'男':'女'}}
					</view>
				</view>
				<view class="messageItem">
					<view class="lable">
						学校
					</view>
					<view class="value">
						{{studentInfo.clazz.schoolName || ""}}
					</view>
				</view>
				<view class="messageItem">
					<view class="lable">
						年级班级
					</view>
					<view class="value">
						{{studentInfo.clazz.gradeName || ""}}
						{{studentInfo.clazz.clazzName || ""}}
					</view>
				</view>
			</view>
		</view>

		<view class="">
			<view class="titleBox">
				<image
					:src="role==1?'https://mp.blrwworkshop.com/imgs/student_line.png' :'https://mp.blrwworkshop.com/imgs/lines.png' "
					mode=""></image>
				<view class="">
					家长信息
				</view>
			</view>

			<view class="messageContent">
				<view class="messageItem">
					<view class="lable">
						家长姓名
					</view>
					<view class="value">
						{{parentsInfo.name || ""}}
					</view>
				</view>
				<view class="messageItem">
					<view class="lable">
						与学生关系
					</view>
					<view class="value">
						{{parentsInfo.identityType == 1 ?"爸爸":"妈妈"}}
					</view>
				</view>
				<view class="messageItem" @click="handleUpdateMobile">
					<view class="lable">
						手机号
					</view>
					<view class="value">
						{{parentsInfo.phone || ""}}
						<image src="https://mp.blrwworkshop.com/imgs/rightIcon.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>


		<view class="">
			<view class="titleBox">
				<image
					:src="role==1?'https://mp.blrwworkshop.com/imgs/student_line.png' :'https://mp.blrwworkshop.com/imgs/lines.png' "
					mode=""></image>
				<view class="">
					其他
				</view>
			</view>

			<view class="messageContent">
				<view class="messageItem" @click="handleOtherParent">
					<view class="lable">
						其他家长信息
					</view>
					<image src="https://mp.blrwworkshop.com/imgs/rightIcon.png" mode=""></image>
				</view>
				<view class="messageItem" @click="handleOtherStudent">
					<view class="lable">
						其他学生信息
					</view>
					<image src="https://mp.blrwworkshop.com/imgs/rightIcon.png" mode=""></image>
				</view>
				<view class="messageItem" @click="handleOtherequipment">
					<view class="lable">
						常用设备管理
					</view>
					<image src="https://mp.blrwworkshop.com/imgs/rightIcon.png" mode=""></image>
				</view>
			</view>
		</view>


		<view v-if="role==1" class="bottomBox">
			<view class="btns" :class="{bg_student:role==1,bg_parent:role==2}" @click="loginOutshow=true">
				退出登录
			</view>
			<view class="btns" :class="{btns_student_s:role==1,btns_parent_s:role==2}" @click="handleChangeStudent">
				切换其他学生
			</view>
		</view>
		<view v-if="role==2" class="bottomBox">
			<view class="btns btnsparent" :class="{bg_student:role==1,bg_parent:role==2}" @click="loginOutshow=true">
				退出登录
			</view>
		</view>

		<u-modal :show="loginOutshow" title="确定退出账号吗" :showCancelButton="true" @cancel="loginOutshow = false"
			cancelColor="#000000" confirmColor="#576B95" @confirm="handleLoginout"></u-modal>
	</view>
</template>

<script>
	import {
		getStudentInfo,
		getFirstParentsInfo,
		logout
	} from "@/api/mine.js"
	export default {
		data() {
			return {
				role: uni.getStorageSync("role"),
				loginOutshow: false,
				studentInfo: {},
				parentsInfo: {},

			}
		},
		onShow() {
			this.handleGetStudentInfo()
			this.handleGetFirstParentsInfo()
		},
		methods: {
			//获取学生信息
			async handleGetStudentInfo() {
				let res = await getStudentInfo()
				if (res.code == 200) {
					this.studentInfo = res
				}
			},
			//获取学生信息
			async handleGetFirstParentsInfo() {
				let res = await getFirstParentsInfo()
				if (res.code == 200) {
					this.parentsInfo = res.data
				}
			},
			async handleLoginout() {
				uni.showLoading({
					title: "正在退出",
					mask: true
				});
				let res = await logout()
				if (res.code == 200) {
					this.loginOutshow = false
					setTimeout(() => {
						uni.hideLoading()
						uni.removeStorageSync('token')
						uni.removeStorageSync('role')
						uni.reLaunch({
							url: "/pages/login/loginType"
						})
					}, 1500)
				} else {
					uni.hideLoading()
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			handleChangeStudent() {
				uni.navigateTo({
					url: "/pages/minePackage/otherStudents/otherStudents"
				})
			},
			handleUpdateMobile() {
				uni.navigateTo({
					url: "/pages/minePackage/updateMobile/updateMobile"
				})
			},
			handleOtherParent() {
				uni.navigateTo({
					url: "/pages/minePackage/ortherParent/ortherParent"
				})
			},
			handleOtherStudent() {
				uni.navigateTo({
					url: "/pages/minePackage/otherStudent/otherStudent"
				})
			},
			handleOtherequipment() {
				uni.navigateTo({
					url: "/pages/minePackage/equipment/equipment"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.setPage {
		width: 100%;
		min-height: 100vh;
		background-color: #F9F9F9;
		padding-bottom: 150rpx;

		.titleBox {
			width: 100%;
			padding: 32rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			font-weight: 600;
			font-size: 36rpx;
			color: #333333;

			image {
				width: 8rpx;
				height: 40rpx;
				margin-right: 15rpx;
			}
		}

		.messageContent {
			width: 100%;

			.messageItem {
				width: 100%;
				padding: 24rpx 32rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: space-between;
				background-color: #ffffff;

				.lable {
					font-weight: 550;
					font-size: 28rpx;
					color: #333333;
					line-height: 40rpx;
				}

				.value {
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
					display: flex;
					align-items: center;
				}

				image {
					width: 48rpx;
					height: 48rpx;
				}

			}

		}


		.bottomBox {
			width: 100%;
			padding: 20rpx 30rpx;
			padding-bottom: 50rpx;
			box-sizing: border-box;
			background-color: #ffffff;
			position: fixed;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.btns {
				width: 320rpx;
				height: 80rpx;
				border-radius: 40rpx;
				font-weight: 500;
				font-size: 32rpx;
				line-height: 80rpx;
				text-align: center;
			}

			.btnsparent {
				width: 100%;
			}
		}



	}
</style>